package com.jtattoo.demo.app;

import com.jtattoo.plaf.luna.LunaLookAndFeel;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author michael hagen
 */
public class TabRenderingProblem2 {

    public static void main(String[] args) {

        try {
            UIManager.setLookAndFeel(new LunaLookAndFeel());
        } catch (UnsupportedLookAndFeelException e) {
        }

        JFrame frame = new JFrame();
        frame.setLayout(new BorderLayout());

        final JLabel label = new JLabel("NDERBARER TEXT");

        final JTabbedPane panel = new JTabbedPane();

        frame.add(panel, BorderLayout.CENTER);


        JButton newTab = new JButton("neues tab");

        newTab.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                panel.add(new JPanel());
                final JLabel label = new JLabel("text" + panel.getTabCount());
                Icon cutIcon = new ImageIcon("D:\\Projekte\\MyProjects\\JTattooDemo\\src\\com\\jtattoo\\demo\\images\\cut.png");
                Icon closerIcon = new ImageIcon("D:\\Projekte\\MyProjects\\JTattooDemo\\src\\com\\jtattoo\\demo\\images\\closer.gif");

                final JPanel header = new JPanel(new BorderLayout(5, 5));

                header.add(new JLabel(closerIcon), BorderLayout.WEST);
                header.add(label, BorderLayout.CENTER);
                header.add(new JLabel(cutIcon), BorderLayout.EAST);
                header.setOpaque(false);
                panel.setTabComponentAt(panel.getTabCount() - 1, header);


                TimerTask tt = new TimerTask() {

                    public void run() {
                        label.setFont(new Font("Dialog", Font.BOLD, 13));
                    }
                };

                Timer t = new Timer();
                t.schedule(tt, 2000);
            }
        });

        frame.add(newTab, BorderLayout.SOUTH);

        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }

        });

        frame.setSize(500, 200);
        frame.setVisible(true);

    }
}
